package com.vip.web.controller;



import com.vip.dao.order.domain.MainMenu;
import com.vip.dao.order.domain.ShopOrder;
import com.vip.dao.shop.domain.ShopCar;
import com.vip.dao.shop.domain.ShopComm;
import com.vip.service.order.MainMenuService;

import com.vip.service.order.ShopOrderService;
import com.vip.service.shop.ShopCarService;
import com.vip.service.shop.ShopCommService;
import com.vip.web.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Api(value = "商店接口")
@RestController
public class ShopController {




    @Autowired
    ShopCommService shopCommService;   

    @Autowired
    ShopCarService shopCarService;

    @Autowired
    ShopOrderService orderService;




    /**
     *
     * @return
     */
    @ApiOperation(value = "查找所有商品")
    @ResponseBody
    @RequestMapping(value = "/shop/findAllcomm",method = RequestMethod.GET)
    public Result findAllComm(){
        List<ShopComm> menuList = shopCommService.findAllByType("商店");
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","获取菜单列表成功");
        map.put("status",200);
        return Result.success(menuList,map);
    }



    @ApiOperation(value = "添加商品到库存")
    @ResponseBody
    @RequestMapping(value = "/shop/addcomm",method = RequestMethod.POST)
    public Result addComm(ShopComm shopComm){
        ShopComm shopComm1 = shopCommService.findCommByName(shopComm.getName());
        if(null == shopComm1){
            shopComm.setType("商店");
            ShopComm shopComm2 = shopCommService.addComm(shopComm);
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","添加成功");
            map.put("status",200);
            return Result.success(shopComm,map);
        }else{
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","请不要重复添加商品，此商品已在仓库");
            map.put("status",200);
            return Result.success(shopComm,map);
        }

    }

    @ApiOperation(value = "添加商品到购物车")
    @ResponseBody
    @RequestMapping(value = "/shop/addCommToCar",method = RequestMethod.GET)
    public Result addCommToCar(Integer uid,String commNames){
        ShopOrder order = new ShopOrder();

        order.setUid(uid.longValue());
        order.setCommons(commNames);

        ShopCar shopCar = shopCarService.addCarComm(uid,commNames);
        ShopOrder shopOrder = orderService.addOrder(order);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加购物车成功");
        map.put("status",200);
        return Result.success(shopOrder,map);
    }






}
